/******************************************************************************
 *  Copyright 2013 Bernhard Grünewaldt                                        *
 *                                                                            *
 *  Licensed under the Apache License, Version 2.0 (the "License");           *
 *  you may not use this file except in compliance with the License.          *
 *  You may obtain a copy of the License at                                   *
 *                                                                            *
 *      http://www.apache.org/licenses/LICENSE-2.0                            *
 *                                                                            *
 *  Unless required by applicable law or agreed to in writing, software       *
 *  distributed under the License is distributed on an "AS IS" BASIS,         *
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
 *  See the License for the specific language governing permissions and       *
 *  limitations under the License.                                            *
 ******************************************************************************/
package com.google.code.greenwood.confluencemavenreleaseinfomacro.pojo;

import java.util.Collection;
import java.util.Set;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;

public class Properties implements Cloneable {
	
	private String propertyName;
	
	private String propertyValue;

	public String getPropertyName() {
		return propertyName;
	}

	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	public String getPropertyValue() {
		return propertyValue;
	}

	public void setPropertyValue(String propertyValue) {
		this.propertyValue = propertyValue;
	}
	
	
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((propertyName == null) ? 0 : propertyName.hashCode());
		return result;
	}

	/**
	 * equals Method must only compare propertyName!
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Properties other = (Properties) obj;
		if (propertyName == null) {
			if (other.propertyName != null)
				return false;
		} else if (!propertyName.equals(other.propertyName))
			return false;
		return true;
	}

	/**
	 * equals Method must only compare propertyName!
	 */
	public static ImmutableSet<Properties> getUnionOfModuleReleaseVersionPropertiesLists(Collection<Properties> moduleReleaseVersionOneProperties, Collection<Properties> moduleReleaseVersionTwoProperties) {
	    Set<Properties> firstSet = ImmutableSet.copyOf(moduleReleaseVersionOneProperties);
	    Set<Properties> secondSet = ImmutableSet.copyOf(moduleReleaseVersionTwoProperties);
	
	    SetView<Properties> unionView = Sets.union(firstSet, secondSet);
	    ImmutableSet<Properties> finalSet = unionView.immutableCopy();
	    
	    return finalSet;
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		Properties clone = new Properties();
		clone.setPropertyName(this.propertyName);
		clone.setPropertyValue(this.propertyValue);
		return clone;
	}
	
	
}
